const app = new Vue({
    el: "#app",
    data: {
        customerId: "o5GGA4gB5o5tm3Cc6z-th6IUxIWY",
        formData: {
            SpecialRequirement: [
                "优质学区",
                "离地铁近",
                "生活便利",
                "南北通透",
                "车位充足",
                "高楼层",
                "中间楼层",
                "绿化率高",
                "优质物业",
            ],
            specialRequirement:
                "优质学区,离地铁近,生活便利,南北通透,车位充足,高楼层,中间楼层,绿化率高,优质物业",
            whichTimeHomeBuyer: "二套",
        },
        phNumber: "15022334455",
        minValue: 1, // slider 左边滑块初始位置
        maxValue: 50, // slider 右边滑块初始位置
        minValueFocus: false,
        idxQ: "0",
        idxT: "0",
        idxM: ["1"],
        houseQty: [
            {
                name: "首套",
                id: "0",
            },
            {
                name: "二套",
                id: "1",
            },
        ],
        houseType: [
            {
                name: "二手房",
                id: "0",
            },
            {
                name: "新房",
                id: "1",
            },
            {
                name: "不限",
                id: "2",
            },
        ],
        houseModel: [
            {
                name: "1居",
                id: "0",
                value: "1",
                isSelected: true,
            },
            {
                name: "2居",
                id: "1",
                value: "2",
                isSelected: false,
            },
            {
                name: "3居",
                id: "2",
                value: "3",
                isSelected: false,
            },
            {
                name: "4居",
                id: "3",
                value: "4",
                isSelected: false,
            },
            {
                name: "5居",
                id: "4",
                value: "5",
                isSelected: false,
            },
            {
                name: "5+居",
                id: "5",
                value: "5+",
                isSelected: false,
            },
        ],
        requireType: [
            {
                id: "1",
                name: "优质学区",
                isSelected: true,
            },
            {
                id: "2",
                name: "离地铁近",
                isSelected: false,
            },
            {
                id: "3",
                name: "生活便利",
                isSelected: false,
            },
            {
                id: "4",
                name: "南北通透",
                isSelected: false,
            },
            {
                id: "5",
                name: "车位充足",
                isSelected: false,
            },
            {
                id: "6",
                name: "高楼层",
                isSelected: false,
            },
            {
                id: "7",
                name: "中间楼层",
                isSelected: false,
            },
            {
                id: "8",
                name: "绿化率高",
                isSelected: false,
            },
            {
                id: "9",
                name: "带电梯",
                isSelected: false,
            },
            {
                id: "10",
                name: "优质物业",
                isSelected: false,
            },
            {
                id: "11",
                name: "不要顶层",
                isSelected: false,
            },
            {
                id: "12",
                name: "不要底层",
                isSelected: false,
            },
        ],
        district: [
            {
                flex: 1,
                values: [],
                className: "slot1",
            },
        ],
        districtName: "不限",
        changeName: "",
        popupVisible: false,
    },
    mounted() {
        this.getBasicData();
    },
    methods: {
        onConfirm() {
            this.popupVisible = false;
            this.districtName = this.changeName;
        },
        onChange(picker, values) {
            this.changeName = values[0];
        },
        async getBasicData() {
            let resData = await axios.get(
                `${rht_server}BasicDataApi/GetBasicData`
            );
            resData.data.data.districtList.forEach((ele) => {
                this.district[0].values.push(ele.name);
            });
            this.district[0].values.unshift("不限");
        },
        selectHandle(type, item) {
            if (type == "houseQty") {
                this.idxQ = item.id;
            } else if (type == "houseType") {
                this.idxT = item.id;
            } else if (type == "houseModel") {
                item.isSelected = !item.isSelected;
            } else if (type == "requireType") {
                item.isSelected = !item.isSelected;
            }
        },
        submit() {
            let formData = {
                budget: `${this.minValue}_${this.maxValue}`, //预算范围
                whichTimeHomeBuyer: this.idxQ == "0" ? "首套" : "二套",
                preference: "",
                houseLayout: "",
                customerId: this.customerId,
                district: this.districtName,
                specialRequirement: "",
            };
            this.houseType.forEach((ele) => {
                // 购买偏好
                if (ele.id == this.idxT) {
                    formData.preference = ele.name;
                }
            });
            let houseLayout = [];
            this.houseModel.forEach((ele) => {
                // 户型
                if (ele.isSelected) {
                    houseLayout.push(ele.value);
                }
            });
            formData.houseLayout = houseLayout.join(",");
            let specialRequirement = [];
            this.requireType.forEach((ele) => {
                // 特殊要求
                if (ele.isSelected) {
                    specialRequirement.push(ele.name);
                }
            });
            formData.specialRequirement = specialRequirement.join(",");

            console.log(formData);
            axios
                .post(
                    `${rht_server}HelpMeToFindHouse/SubmitHelpMeToFindHouseInfo`,
                    {
                        ...formData,
                    }
                )
                .then((res) => {
                    // 提交以后调用flutter到帮我找房页面
                    console.log(res, "res");
                })
                .catch((err) => {
                    console.log(err);
                });
        },
    },
});
